import FViewModule from "../../Libs/Framework/Support/FViewModule";
import { PlayerVO } from "../../Libs/Framework/VO/Player/PlayerVO";
import { GameDataManager } from "../../Libs/Framework/Managers/GameDataManager";
import { WriteCommand } from "../../Libs/NetWork/WriteCommand/WriteCommand";
import { EventManager } from '../../Libs/Framework/Managers/EventManager';
import { GameEvent } from '../../Libs/Framework/Event/GameEvent';
import { WriteCmdEvent } from "../../Libs/Framework/Event/WriteCmdEvent";

const { ccclass, property } = cc._decorator;
@ccclass
export default class PlayerModule extends FViewModule {
    @property(cc.Sprite)
    private Head:cc.Sprite = null
    @property(cc.Label)
    private Nickname : cc.Label = null
    @property(cc.Label)
    private Score : cc.Label = null
    @property(cc.Node)
    private Ready : cc.Node = null
    @property(cc.Node)
    private ReadyButton : cc.Node = null


    public clearView() : void {
        this.node.active = false
        this.Nickname.string = ""
        this.Score.string = ""
        this.Ready.active = false
        if(this.ReadyButton){
            this.ReadyButton.active = false
        }
    }

    protected addEvents() : void {
        super.addEvents()
        // EventManager.addEvent(GameEvent.ON_GAMESTATUS_CHANGE,)
    }

    

    public showPlayer(data:PlayerVO) : void {
        this.node.active = true
        // this.Head.spriteFrame = null
        this.Nickname.string = data.nickname
        this.Score.string = String(data.score)
        this.Ready.active = data.isReady
        if(data.acId == GameDataManager.game.playerId){
            this.ReadyButton.active = !data.isReady
        }
        
    }


    public setReady(can:boolean) : void{
        this.Ready.active = can
    }

    public setScore(score:string) : void {
        this.Score.string = score
    }

    public setNickname(str:string) : void {
        this.Nickname.string = str
    }

    public setHeadUrl(url:string) : void {
        //this.Head.spriteFrame = null
    }

    public sendReady() : void {
        new WriteCommand(WriteCmdEvent.CMD_Ready)
    }
    
    public update() : void {
        if(CC_EDITOR)return;
    }

}